package com.libcommon.ext

import androidx.appcompat.app.AppCompatActivity
import androidx.multidex.BuildConfig
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.EncodeUtils
import com.blankj.utilcode.util.EncryptUtils
import com.blankj.utilcode.util.ToastUtils

/**
 * CreateBy:Joker
 * CreateTime:2024/8/9 10:35
 * description：
 */

fun String.getNickName(limit: Int = 15): String {
    return if (this.length < limit) this else "${this.substring(0, limit - 2)}..."
}

fun debugToast(str: String) {
    if (BuildConfig.DEBUG) {
        ToastUtils.showShort("debugToast:$str")
    }
}

fun String.getDESDecrypt(): String = if (this.startsWith("http")) this else EncodeUtils.urlDecode(this)

fun String.getFileMD5Name(): String = EncryptUtils.encryptMD5ToString(this)

fun safeGetAppCompatActivity(): AppCompatActivity? {
    runCatching {
        return ActivityUtils.getTopActivity() as? AppCompatActivity?
    }
    return null
}